package com.dk.controller;


import com.dk.data.PageBean;
import com.dk.data.Result;
import com.dk.em.ConstantEnum;
import com.dk.entity.TGoods;
import com.dk.entity.TLabel;
import com.dk.mapper.TLabelMapper;
import com.dk.service.ITLabelService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2021-11-02
 */
@RestController
@RequestMapping("/label")
public class TLabelController {

    @Autowired
    private TLabelMapper labelMapper;

    @Autowired
    private ITLabelService labelService;

    @ApiOperation(value = "后台标签增加功能")
    @ApiImplicitParams({
            @ApiImplicitParam(name="name",value = "标签名",required = true,paramType = "query")
    })
    @PostMapping("add")
    public Result add(TLabel label){
        int i = labelMapper.insert(label);
        if (i > 0){
            return Result.bulid(ConstantEnum.SUCCESS).setResult("标签增加成功");
        }
        return Result.bulid(ConstantEnum.ERROR).setResult("标签增加失败");
    }

    @ApiOperation(value = "后台标题修改功能")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "标签id",required = true,paramType = "query"),
            @ApiImplicitParam(name="name",value = "标签名称",required = true,paramType = "query")
    })
    @PostMapping("update")
    public Result update(TLabel label){
        int i=labelMapper.updateById(label);
        if (i>0){
            return Result.bulid(ConstantEnum.SUCCESS).setResult("标题修改成功");
        }
        return Result.bulid(ConstantEnum.ERROR).setResult("标题修改失败");
    }

    @ApiOperation(value = "后台标题单条删除功能")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "标题id",required = true,paramType = "query"),
    })
    @PostMapping("deleteById")
    public Result deleteById(Long id){
        int i=labelMapper.deleteById(id);
        if (i>0){
            return Result.bulid(ConstantEnum.SUCCESS).setResult("标题单条删除成功");
        }
        return Result.bulid(ConstantEnum.ERROR).setResult("标题单条删除失败");
    }

    @ApiOperation(value = "后台标题批量删除功能")
    @PostMapping("deleteAll")
    public Result deleteAll(){
        boolean b=labelService.removeByIds(Arrays.asList());
        if (b){
            return Result.bulid(ConstantEnum.SUCCESS).setResult("标题批量删除成功");
        }
        return Result.bulid(ConstantEnum.ERROR).setResult("标题批量删除失败");
    }

    @ApiOperation(value = "查询后台标题表")
    @GetMapping("findAllByGoods")
    public Result findAllByMileageAsc(){
        List<TLabel> tLabels = labelMapper.selectList(null);
        return Result.bulid(ConstantEnum.SUCCESS).setResult(tLabels);
    }
}
